<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>水平垂直居中</title>
    <style>
        .wrapper {
            margin: 20px;
            position: relative;
            width: 500px;
            height: 200px;
            background-color: bisque;
        }
        
        .nagivate-margin {
            position: absolute;
            width: 100px;
            height: 100px;
            left: 50%;
            top: 50%;
            margin-top: -50px;
            margin-left: -50px;
            background-color: blueviolet;
        }
        
        .auto-margin {
            position: absolute;
            width: 100px;
            height: 100px;
            background-color: brown;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
        }
        
        .calc-margin {
            position: absolute;
            width: 100px;
            height: 100px;
            background-color: chocolate;
            left: calc(50% - 50px);
            top: calc(50% - 50px);
        }
        
        .transform {
            position: absolute;
            background-color: darkturquoise;
            /* top: 50%;
            left: 50%;
            transform: translate(-50%, -50%); */
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }
    </style>
</head>

<body>
    <h1>position+各种margin</h1>
    <div class="wrapper">
        <div class="nagivate-margin">
        </div>
    </div>
    <div class="wrapper">
        <div class="auto-margin">

        </div>
    </div>
    <div class="wrapper">
        <div class="calc-margin">
        </div>
    </div>
    <div class="wrapper">
        <div class="transform">垂直居中定位</div>
    </div>



</body>

</html>